clear all
set	more off

cd "~/Dropbox/ors_quality_R01"
use "data/KDG/know_do_gap.dta", clear


/* Controls 
Years of experience: ps_b11
Provider age: ps_b06
Number of patients per day: ps_b37
Number of diarrhea cases per week: ps_b39
Competitive market: comp_cat
Sell medicine/attached pharmacy: ps_dispense
Essential Questions Asked: blood in stool, frequency of stool, duration of episode, vomiting
*/

gen experience= 1 if ps_b11 <=10
replace experience= 2 if ps_b11 >10 & ps_b11<=22
replace experience= 3 if ps_b11 >22


gen age_cat= 1 if ps_b06 <=37
replace age_cat= 2 if ps_b06 >37 & ps_b06<=49
replace age_cat= 3 if ps_b06 >49

gen patients_cat= 1 if ps_b37 <=10
replace patients_cat= 2 if ps_b37 >10 & ps_b37<=25
replace patients_cat= 3 if ps_b37 >25

gen diar_cat= 1 if ps_b39 <=2
replace diar_cat= 2 if ps_b39 >2 & ps_b39<=6
replace diar_cat= 3 if ps_b39 >6



reghdfe rec_anti i.prov_type i.experience i.age_cat i.patients_cat i.diar_cat competitive ps_dispense b21c b21d b21g if know_anti==1, abs(town_code)

gen series = 0 if _n==33
replace series = _b[2.prov_type] if _n == 32
replace series = _b[3.prov_type] if _n == 31
replace series = _b[4.prov_type] if _n == 30

replace series = 0 if _n==27
replace series = _b[2.experience] if _n==26
replace series = _b[3.experience] if _n==25

replace series = 0 if _n==22
replace series = _b[2.age_cat] if _n==21
replace series = _b[3.age_cat] if _n==20

replace series = 0 if _n==17
replace series = _b[2.patients_cat] if _n==16
replace series = _b[3.patients_cat] if _n==15

replace series = 0 if _n==12
replace series = _b[2.diar_cat] if _n==11
replace series = _b[3.diar_cat] if _n==10

replace series = _b[b21c] if _n==7
replace series = _b[b21d] if _n==6
replace series = _b[b21g] if _n==5

replace series = _b[competitive] if _n==3
replace series = _b[ps_dispense ] if _n==1

gen se = 0 if _n==33
replace se = _se[2.prov_type] if _n == 32
replace se = _se[3.prov_type] if _n == 31
replace se = _se[4.prov_type] if _n == 30

replace se = 0 if _n==27
replace se = _se[2.experience] if _n==26
replace se = _se[3.experience] if _n==25

replace se = 0 if _n==22
replace se = _se[2.age_cat] if _n==21
replace se = _se[3.age_cat] if _n==20

replace se = 0 if _n==17
replace se = _se[2.patients_cat] if _n==16
replace se = _se[3.patients_cat] if _n==15

replace se = 0 if _n==12
replace se = _se[2.diar_cat] if _n==11
replace se = _se[3.diar_cat] if _n==10

replace se = _se[b21c] if _n==7
replace se = _se[b21d] if _n==6
replace se = _se[b21g] if _n==5

replace se = _se[competitive] if _n==3
replace se = _se[ps_dispense ] if _n==1

gen ub = series + 1.96*se
gen lb = series - 1.96*se

gen axis=_n if _n<=34

#delimit;
label define axis
34	"{bf:PROVIDER TYPE}"
33	"MBBS"
32	"RMP"
31	"AYUSH"
30	"Pharmacy"
29 	" "
28	"{bf:EXPERIENCE}"
27	"<=10 Years"
26	"10-22 years"
25	"22+ years"
24 	" "
23	"{bf:AGE}"
22	"<=27 Years"
21	"37-49 Years"
20	"50+ Years"
19 	" "
18	"{bf:PATIENTS PER DAY}"
17	"<=10 patients"
16	"10-25 patients"
15	"25+ patiens"
14 	" "
13	"{bf:DIARHEA PATIENTS PER WEEK}"
12	"<=2 patients"
11	"2-6 patients"
10	"6+ patients"
9 	" "
8	"{bf:KEY QUESTIONS}"
7	"Blood in stool?"
6	"Frequency of loose stool?"
5	"Duration of symptoms?"
4 	" "
3	"{bf:COMPETITIVE MARKET}"
2 	" "
1	"{bf:DISPENSES MEDS}";
#delimit cr

label values axis axis



twoway(scatter axis series if _n>=30, color(navy*.5))(rcap  lb ub axis if _n>=30, horizontal  color(navy*.5) ) ///
(scatter axis series if inrange(axis, 25, 28) , color(red*.5))(rcap  lb ub axis if inrange(axis, 25, 28), horizontal  color(red*.5) ) ///
(scatter axis series if inrange(axis, 20, 23) , color(navy*.5))(rcap  lb ub axis if inrange(axis, 20, 23), horizontal  color(navy*.5) ) ///
(scatter axis series if inrange(axis, 15, 18) , color(red*.5))(rcap  lb ub axis if inrange(axis, 15, 18), horizontal  color(red*.5) ) ///
(scatter axis series if inrange(axis, 10, 13) , color(navy*.5))(rcap  lb ub axis if inrange(axis, 10, 13), horizontal  color(navy*.5) ) ///
(scatter axis series if inrange(axis, 5, 8) , color(red*.5))(rcap  lb ub axis if inrange(axis, 5, 8) , horizontal  color(red*.5) ) ///
(scatter axis series if _n ==3 , color(navy*.5))(rcap  lb ub axis if _n ==3, horizontal  color(navy*.5) ) /// 
(scatter axis series if _n ==1 , color(red*.5))(rcap  lb ub axis if _n ==1, horizontal  color(red*.5) ) , ///
xline(0, lpattern(dash) lcolor(black)) ///
xlabel(-0.4(.1)0.4,grid gstyle(dot)) ///
ytitle(" ") ///
xtitle("Difference in know-do gap") ///
legend(off) ///
ylabel(0(1)34, angle(0) notick labsize(small) valuelabels)


graph export "figures/drivers_prescribing_gap.pdf", replace

